﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Manager_EditAdmin : System.Web.UI.Page
{
    CommonClass ccobj = new CommonClass();
    DBClass dbobj = new DBClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindddlist();
            binddata();
        }
    }
    protected void bindddlist()
    {
        string strsql = "select * from Department";
        DataTable dstable = dbobj.GetDataSet(strsql, "tabdepartment");
        DropDownList1.DataSource = dstable.DefaultView;
        DropDownList1.DataTextField = dstable.Columns[1].ToString();
        DropDownList1.DataValueField = dstable.Columns[0].ToString();
        DropDownList1.DataBind();
    }
    protected void binddata()
    {
        string strsql = "select * from Admin where AdminID='" + Request.QueryString["id"].ToString() + "'";
        DataTable dstable = dbobj.GetDataSet(strsql, "tabadmin");
        if (dstable.Rows.Count > 0)
        {
            TextBox1.Text = dstable.Rows[0][0].ToString();
            TextBox2.Text = dstable.Rows[0][1].ToString();
            foreach (ListItem li in DropDownList1.Items)
            {
                if (li.Value == dstable.Rows[0][3].ToString())
                    li.Selected = true;
            }

            if (Convert.ToInt32(dstable.Rows[0][4].ToString()) == 0)
                CheckBox1.Checked = false;
            else
                CheckBox1.Checked = true;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strsql = "update Admin set AdminName='" + TextBox2.Text.Trim() + "',DepartmentID='" + DropDownList1.SelectedValue.ToString() + "',IsAssessMan=" + (CheckBox1.Checked ? 1 : 0) + " where AdminID='" + TextBox1.Text.Trim() + "'";
        dbobj.ExecNonQuery(strsql);
        Response.Write(ccobj.MessageBox("更新成功！"));
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Manager/ListAdmin.aspx");
    }
}